home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
RTF
/
rtftoken.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
21KB
|
678 lines
/* rtf.C from
reader.c - RTF file reader. Distribution 1.06.
ASCII 10 (\n) and 13 (\r) are ignored and silently discarded.
(The read hook will still get a look at them.)
"\:" is not a ":", it's a control symbol. But some versions of
Word seem to write "\:" for ":". This reader treats "\:" as a
plain text ":"
*/
extern "C" {
# include <ctype.h>
}
# include <assert.h>
# include <string.h>
# include "rtftoken.h"
static int GetChar ();
static int HexVal (char);
static void LookupInit ();
static int Hash (const char*);
int RTF::inited = 0;
RTF::RTF()
{
if(!inited)
inited=1, LookupInit();
rtfTextBuf[0] = 0;
rtfClass = Unknown;
};
/* ---------------------------------------------------------------------- */
/*
Token reading routines
*/
/*
Read the input stream, invoking the writer's callbacks
where appropriate.
*/
void RTF::SkipGroup ()
{
int level = 1;
do{
if (rtfClass == Group)
{
if (rtfMajor == BeginGroup)
++level;
else if (rtfMajor == EndGroup)
{
if (--level < 1)
break; /* end of initial group */
}
}
}while (GetToken () != Eof);
}
/*
Read one token. Call the read hook if there is one. The
token class is the return value. Returns RTF::Eof when there
are no more tokens.
*/
int RTF::GetToken ()
{
_GetToken ();
/* \n and \r are noise tokens */
if (rtfClass == Text
&& (rtfMajor == '\n' || rtfMajor == '\r'))
rtfClass = Unknown;
return (rtfClass);
}
void RTF::_GetToken ()
{
int sign;
int c;
/* initialize token vars */
rtfClass = Unknown;
rtfParam = 0;
rtfMinor = 0;
rtfTextBuf[rtfTextLen = 0] = '\0';
/* get first character, which may be a pushback from previous token */
if ((c = GetChar ()) == EOF)
{
rtfClass = EOF;
return;
}
if (c == '{')
{
rtfClass = Group;
rtfMajor = BeginGroup;
return;
}
if (c == '}')
{
rtfClass = Group;
rtfMajor = EndGroup;
return;
}
if (c != '\\')
{
/*
Two possibilities here:
1) ASCII 9, effectively like \tab control symbol
2) literal text char
*/
if (c == '\t') /* ASCII 9 */
{
rtfClass = Control;
rtfMajor = SpecialChar;
rtfMinor = Tab;
}
else
{
rtfClass = Text;
rtfMajor = c;
}
return;
}
if ((c = GetChar ()) == EOF)
{
/* early eof, whoops (class is rtfUnknown) */
return;
}
if (!isalpha (c))
{
/*
Three possibilities here:
1) hex encoded text char, e.g., \'d5, \'d3
2) special escaped text char, e.g., \{, \}
3) control symbol, e.g., \_, \-, \|, \<10>
*/
if (c == '\'') /* hex char */
{
int c2;
if ((c = GetChar ()) != EOF && (c2 = GetChar ()) != EOF)
{
/* should do isxdigit check! */
rtfClass = Text;
rtfMajor = HexVal (c) * 16 + HexVal (c2);
rtfMinor = 1;
return;
}
/* early eof, whoops (class is rtfUnknown) */
return;
}
if (strchr (":{}\\", c) != NULL) /* escaped char */
{
rtfClass = Text;
rtfMajor = c;
rtfMinor = 2;
return;
}
/* control symbol */
Lookup (rtfTextBuf); /* sets class, major, minor */
return;
}
/* control word */
while (isalpha (c))
{
if ((c = GetChar ()) == EOF)
break;
}
/*
At this point, the control word is all collected, so the
major/minor numbers are determined before the parameter
(if any) is scanned. There will be one too many characters
in the buffer, though, so fix up before and restore after
looking up.
*/
if (c != EOF)
rtfTextBuf[rtfTextLen-1] = '\0';
Lookup (rtfTextBuf); /* sets class, major, minor */
if (c != EOF)
rtfTextBuf[rtfTextLen-1] = c;
/*
Should be looking at first digit of parameter if there
is one, unless it's negative. In that case, next char
is '-', so need to gobble next char, and remember sign.
*/
sign = 1;
if (c == '-')
{
sign = -1;
c = GetChar ();
}
if (c != EOF)
{
if(!isdigit(c)) rtfParam = 1; /* so \b defaults to \b1 */
while (isdigit (c)) /* gobble parameter */
{
rtfParam = rtfParam * 10 + c - '0';
if ((c = GetChar ()) == EOF)
break;
}
rtfParam *= sign;
}
/*
If control symbol delimiter was a blank, gobble it.
Otherwise the character is first char of next token, so
push it back for next call. In either case, delete the
delimiter from the token buffer.
*/
if (c != EOF)
{
if (c != ' ')
pushback(c);
rtfTextBuf[--rtfTextLen] = '\0';
}
return;
}
/*
Distributions up through 1.04 assumed high bit could be set in
RTF file characters. Beginning with 1.05, that's not true, but
still check and die if such a character is found.
*/
int RTF::GetChar ()
{
int c = next_char();
rtfTextBuf[rtfTextLen++] = c;
if (c == NULL)
{
rtfTextLen--;
c = EOF;
}
return c;
}
int HexVal (char c)
{
if (isupper (c))
c = tolower (c);
if (isdigit (c))
return (c - '0'); /* '0'..'9' */
return (c - 'a' + 10); /* 'a'..'f' */
}
/*
A minor number of -1 means the token has no minor number
(all valid minor numbers are >= 0).
*/
typedef struct
{
int rtfKMajor; /* major number */
int rtfKMinor; /* minor number */
char *rtfKStr; /* symbol name */
int rtfKHash; /* symbol name hash value */
}RTFKey;
static RTFKey rtfKey[] =
{
RTF::SpecialChar, RTF::CurHeadPict, "chpict", 0, /* ?? */
RTF::SpecialChar, RTF::CurHeadDate, "chdate", 0,
RTF::SpecialChar, RTF::CurHeadTime, "chtime", 0,
RTF::SpecialChar, RTF::CurHeadPage, "chpgn", 0,
RTF::SpecialChar, RTF::CurFNote, "chftn", 0,
RTF::SpecialChar, RTF::CurAnnotRef, "chatn", 0,
RTF::SpecialChar, RTF::FNoteSep, "chftnsep", 0,
RTF::SpecialChar, RTF::FNoteCont, "chftnsepc", 0,
RTF::SpecialChar, RTF::Formula, "|", 0,
RTF::SpecialChar, RTF::NoBrkSpace, "~", 0,
RTF::SpecialChar, RTF::NoReqHyphen, "-", 0,
RTF::SpecialChar, RTF::NoBrkHyphen, "_", 0,
RTF::SpecialChar, RTF::Cell, "cell", 0,
RTF::SpecialChar, RTF::Row, "row", 0,
RTF::SpecialChar, RTF::Par, "par", 0,
RTF::SpecialChar, RTF::Par, "\n", 0,
RTF::SpecialChar, RTF::Par, "\r", 0,
RTF::SpecialChar, RTF::Sect, "sect", 0,
RTF::SpecialChar, RTF::Page, "page", 0,
RTF::SpecialChar, RTF::Column, "column", 0,
RTF::SpecialChar, RTF::Line, "line", 0,
RTF::SpecialChar, RTF::Tab, "tab", 0,
RTF::SpecialChar, RTF::OptDest, "*", 0,
RTF::SpecialChar, RTF::IIntVersion, "vern", 0,
RTF::SpecialChar, RTF::ICreateTime, "creatim", 0,
RTF::SpecialChar, RTF::IRevisionTime, "revtim", 0,
RTF::SpecialChar, RTF::IPrintTime, "printim", 0,
RTF::SpecialChar, RTF::IBackupTime, "buptim", 0,
RTF::SpecialChar, RTF::IEditTime, "edmins", 0,
RTF::SpecialChar, RTF::IYear, "yr", 0,
RTF::SpecialChar, RTF::IMonth, "mo", 0,
RTF::SpecialChar, RTF::IDay, "dy", 0,
RTF::SpecialChar, RTF::IHour, "hr", 0,
RTF::SpecialChar, RTF::IMinute, "min", 0,
RTF::SpecialChar, RTF::INPages, "nofpages", 0,
RTF::SpecialChar, RTF::INWords, "nofwords", 0,
RTF::SpecialChar, RTF::INChars, "nofchars", 0,
RTF::SpecialChar, RTF::IIntID, "id", 0,
RTF::CharAttr, RTF::Plain, "plain", 0,
RTF::CharAttr, RTF::Bold, "b", 0,
RTF::CharAttr, RTF::Italic, "i", 0,
RTF::CharAttr, RTF::StrikeThru, "strike", 0,
RTF::CharAttr, RTF::Outline, "outl", 0,
RTF::CharAttr, RTF::Shadow, "shad", 0,
RTF::CharAttr, RTF::SmallCaps, "scaps", 0,
RTF::CharAttr, RTF::AllCaps, "caps", 0,
RTF::CharAttr, RTF::Invisible, "v", 0,
RTF::CharAttr, RTF::FontNum, "f", 0,
RTF::CharAttr, RTF::FontSize, "fs", 0,
RTF::CharAttr, RTF::Expand, "expnd", 0,
RTF::CharAttr, RTF::Underline, "ul", 0,
RTF::CharAttr, RTF::WUnderline, "ulw", 0,
RTF::CharAttr, RTF::DUnderline, "uld", 0,
RTF::CharAttr, RTF::DbUnderline, "uldb", 0,
RTF::CharAttr, RTF::NoUnderline, "ulnone", 0,
RTF::CharAttr, RTF::SuperScript, "up", 0,
RTF::CharAttr, RTF::SubScript, "dn", 0,
RTF::CharAttr, RTF::Revised, "revised", 0,
RTF::CharAttr, RTF::ForeColor, "cf", 0,
RTF::CharAttr, RTF::BackColor, "cb", 0,
RTF::ParAttr, RTF::ParDef, "pard", 0,
RTF::ParAttr, RTF::StyleNum, "s", 0,
RTF::ParAttr, RTF::QuadLeft, "ql", 0,
RTF::ParAttr, RTF::QuadRight, "qr", 0,
RTF::ParAttr, RTF::QuadJust, "qj", 0,
RTF::ParAttr, RTF::QuadCenter, "qc", 0,
RTF::ParAttr, RTF::FirstIndent, "fi", 0,
RTF::ParAttr, RTF::LeftIndent, "li", 0,
RTF::ParAttr, RTF::RightIndent, "ri", 0,
RTF::ParAttr, RTF::SpaceBefore, "sb", 0,
RTF::ParAttr, RTF::SpaceAfter, "sa", 0,
RTF::ParAttr, RTF::SpaceBetween, "sl", 0,
RTF::ParAttr, RTF::InTable, "intbl", 0,
RTF::ParAttr, RTF::Keep, "keep", 0,
RTF::ParAttr, RTF::KeepNext, "keepn", 0,
RTF::ParAttr, RTF::SideBySide, "sbys", 0,
RTF::ParAttr, RTF::PBBefore, "pagebb", 0,
RTF::ParAttr, RTF::NoLineNum, "noline", 0,
RTF::ParAttr, RTF::TabPos, "tx", 0,
RTF::ParAttr, RTF::TabRight, "tqr", 0,
RTF::ParAttr, RTF::TabCenter, "tqc", 0,
RTF::ParAttr, RTF::TabDecimal, "tqdec", 0,
RTF::ParAttr, RTF::TabBar, "tb", 0,
RTF::ParAttr, RTF::BorderTop, "brdrt", 0,
RTF::ParAttr, RTF::BorderBottom, "brdrb", 0,
RTF::ParAttr, RTF::BorderLeft, "brdrl", 0,
RTF::ParAttr, RTF::BorderRight, "brdrr", 0,
RTF::ParAttr, RTF::BorderBar, "bar", 0,
RTF::ParAttr, RTF::BorderBox, "box", 0,
RTF::ParAttr, RTF::BorderBetween, "brdrbtw", 0,
RTF::ParAttr, RTF::BorderSingle, "brdrs", 0,
RTF::ParAttr, RTF::BorderThick, "brdrth", 0,
RTF::ParAttr, RTF::BorderShadow, "brdrsh", 0,
RTF::ParAttr, RTF::BorderDouble, "brdrdb", 0,
RTF::ParAttr, RTF::BorderDot, "brdrdot", 0,
RTF::ParAttr, RTF::BorderHair, "brdrhair", 0,
RTF::ParAttr, RTF::LeaderDot, "tldot", 0,
RTF::ParAttr, RTF::LeaderHyphen, "tlhyph", 0,
RTF::ParAttr, RTF::LeaderUnder, "tlul", 0,
RTF::ParAttr, RTF::LeaderThick, "tlth", 0,
RTF::ParAttr, RTF::BorderSpace, "brsp", 0,
RTF::SectAttr, RTF::SectDef, "sectd", 0,
/*rtfSectAttr, RTF::NoBreak, "nobreak", 0,
RTF::SectAttr, RTF::ColBreak, "colbreak", 0,
RTF::SectAttr, RTF::PageBreak, "pagebreak", 0,
RTF::SectAttr, RTF::EvenBreak, "evenbreak", 0,
RTF::SectAttr, RTF::OddBreak, "oddbreak", 0,*/
RTF::SectAttr, RTF::NoBreak, "sbknone", 0,
RTF::SectAttr, RTF::ColBreak, "sbkcol", 0,
RTF::SectAttr, RTF::PageBreak, "sbkpage", 0,
RTF::SectAttr, RTF::EvenBreak, "sbkeven", 0,
RTF::SectAttr, RTF::OddBreak, "sbkodd", 0,
RTF::SectAttr, RTF::PageCont, "pgncont", 0,
RTF::SectAttr, RTF::PageStarts, "pgnstarts", 0,
RTF::SectAttr, RTF::PageRestart, "pgnrestart", 0,
RTF::SectAttr, RTF::PageDecimal, "pgndec", 0,
RTF::SectAttr, RTF::PageURoman, "pgnucrm", 0,
RTF::SectAttr, RTF::PageLRoman, "pgnlcrm", 0,
RTF::SectAttr, RTF::PageULetter, "pgnucltr", 0,
RTF::SectAttr, RTF::PageLLetter, "pgnlcltr", 0,
RTF::SectAttr, RTF::PageNumLeft, "pgnx", 0,
RTF::SectAttr, RTF::PageNumTop, "pgny", 0,
RTF::SectAttr, RTF::HeaderY, "headery", 0,
RTF::SectAttr, RTF::FooterY, "footery", 0,
RTF::SectAttr, RTF::LineModulus, "linemod", 0,
RTF::SectAttr, RTF::LineDist, "linex", 0,
RTF::SectAttr, RTF::LineStarts, "linestarts", 0,
RTF::SectAttr, RTF::LineRestart, "linerestart", 0,
RTF::SectAttr, RTF::LineRestartPg, "lineppage", 0,
RTF::SectAttr, RTF::LineCont, "linecont", 0,
RTF::SectAttr, RTF::TopVAlign, "vertalt", 0,
RTF::SectAttr, RTF::BottomVAlign, "vertal", 0,
RTF::SectAttr, RTF::CenterVAlign, "vertalc", 0,
RTF::SectAttr, RTF::JustVAlign, "vertalj", 0,
RTF::SectAttr, RTF::Columns, "cols", 0,
RTF::SectAttr, RTF::ColumnSpace, "colsx", 0,
RTF::SectAttr, RTF::ColumnLine, "linebetcol", 0,
RTF::SectAttr, RTF::ENoteHere, "endnhere", 0,
RTF::SectAttr, RTF::TitleSpecial, "titlepg", 0,
RTF::DocAttr, RTF::PaperWidth, "paperw", 0,
RTF::DocAttr, RTF::PaperHeight, "paperh", 0,
RTF::DocAttr, RTF::LeftMargin, "margl", 0,
RTF::DocAttr, RTF::RightMargin, "margr", 0,
RTF::DocAttr, RTF::TopMargin, "margt", 0,
RTF::DocAttr, RTF::BottomMargin, "margb", 0,
RTF::DocAttr, RTF::FacingPage, "facingp", 0,
RTF::DocAttr, RTF::GutterWid, "gutter", 0,
RTF::DocAttr, RTF::DefTab, "deftab", 0,
RTF::DocAttr, RTF::WidowCtrl, "widowctrl", 0,
RTF::DocAttr, RTF::HyphHotZone, "hyphhotz", 0,
RTF::DocAttr, RTF::FNoteEndSect, "endnotes", 0,
RTF::DocAttr, RTF::FNoteEndDoc, "enddoc", 0,
RTF::DocAttr, RTF::FNoteBottom, "ftnbj", 0,
RTF::DocAttr, RTF::FNoteText, "ftntj", 0,
RTF::DocAttr, RTF::FNoteStart, "ftnstart", 0,
RTF::DocAttr, RTF::FNoteRestart, "ftnrestart", 0,
RTF::DocAttr, RTF::PageStart, "pgnstart", 0,
RTF::DocAttr, RTF::LineStart, "linestart", 0,
RTF::DocAttr, RTF::Landscape, "landscape", 0,
RTF::DocAttr, RTF::FracWidth, "fracwidth", 0,
RTF::DocAttr, RTF::NextFile, "nextfile", 0,
RTF::DocAttr, RTF::Template, "template", 0,
RTF::DocAttr, RTF::MakeBackup, "makeback", 0,
RTF::DocAttr, RTF::RTFDefault, "defformat", 0,
RTF::DocAttr, RTF::Revisions, "revisions", 0,
RTF::DocAttr, RTF::MirrorMargin, "margmirror", 0,
RTF::DocAttr, RTF::RevDisplay, "revprop", 0,
RTF::DocAttr, RTF::RevBar, "revbar", 0,
RTF::StyleAttr, RTF::BasedOn, "sbasedon", 0,
RTF::StyleAttr, RTF::Next, "snext", 0,
RTF::PictAttr, RTF::MacQD, "macpict", 0,
RTF::PictAttr, RTF::WinMetafile, "wmetafile", 0,
RTF::PictAttr, RTF::WinBitmap, "wbitmap", 0,
RTF::PictAttr, RTF::PicWid, "picw", 0,
RTF::PictAttr, RTF::PicHt, "pich", 0,
RTF::PictAttr, RTF::PicGoalWid, "picwgoal", 0,
RTF::PictAttr, RTF::PicGoalWid, "picwGoal", 0,
RTF::PictAttr, RTF::PicGoalHt, "pichgoal", 0,
RTF::PictAttr, RTF::PicGoalHt, "pichGoal", 0,
RTF::PictAttr, RTF::PicScaleX, "picscalex", 0,
RTF::PictAttr, RTF::PicScaleY, "picscaley", 0,
RTF::PictAttr, RTF::PicScaled, "picscaled", 0,
RTF::PictAttr, RTF::PicCropTop, "piccropt", 0,
RTF::PictAttr, RTF::PicCropBottom, "piccropb", 0,
RTF::PictAttr, RTF::PicCropLeft, "piccropl", 0,
RTF::PictAttr, RTF::PicCropRight, "piccropr", 0,
RTF::PictAttr, RTF::PixelBits, "wbmbitspixel", 0,
RTF::PictAttr, RTF::BitmapPlanes, "wbmplanes", 0,
RTF::PictAttr, RTF::BitmapWid, "wbmwidthbytes", 0,
RTF::PictAttr, RTF::PicBinary, "bin", 0,
RTF::Destination, RTF::Pict, "pict", 0,
/* @@ NeXT RTF hacks */
RTF::Destination, RTF::Pict, "NGDocument", 0,
RTF::Destination, RTF::Pict, "NGGraphic", 0,
RTF::Destination, RTF::Footnote, "footnote", 0,
RTF::Destination, RTF::Header, "header", 0,
RTF::Destination, RTF::HeaderLeft, "headerl", 0,
RTF::Destination, RTF::HeaderRight, "headerr", 0,
RTF::Destination, RTF::HeaderFirst, "headerf", 0,
RTF::Destination, RTF::Footer, "footer", 0,
RTF::Destination, RTF::FooterLeft, "footerl", 0,
RTF::Destination, RTF::FooterRight, "footerr", 0,
RTF::Destination, RTF::FooterFirst, "footerf", 0,
RTF::Destination, RTF::FNSep, "ftnsep", 0,
RTF::Destination, RTF::FNContSep, "ftnsepc", 0,
RTF::Destination, RTF::FNContNotice, "ftncn", 0,
RTF::Destination, RTF::Info, "info", 0,
RTF::Destination, RTF::StyleSheet, "stylesheet", 0,
RTF::Destination, RTF::FontTbl, "fonttbl", 0,
RTF::Destination, RTF::ColorTbl, "colortbl", 0,
RTF::Destination, RTF::Annotation, "annotation", 0,
RTF::Destination, RTF::AnnotID, "atnid", 0,
RTF::Destination, RTF::Field, "field", 0,
RTF::Destination, RTF::FieldInst, "fldinst", 0,
RTF::Destination, RTF::FieldResult, "fldrslt", 0,
RTF::Destination, RTF::Index, "xe", 0,
RTF::Destination, RTF::IndexBold, "bxe", 0,
RTF::Destination, RTF::IndexItalic, "ixe", 0,
RTF::Destination, RTF::IndexText, "txe", 0,
RTF::Destination, RTF::IndexRange, "rxe", 0,
RTF::Destination, RTF::TOC, "tc", 0,
RTF::Destination, RTF::BookmarkStart, "bkmkstart", 0,
RTF::Destination, RTF::BookmarkEnd, "bkmkend", 0,
RTF::Destination, RTF::ITitle, "title", 0,
RTF::Destination, RTF::ISubject, "subject", 0,
RTF::Destination, RTF::IAuthor, "author", 0,
RTF::Destination, RTF::IOperator, "operator", 0,
RTF::Destination, RTF::IKeywords, "keywords", 0,
RTF::Destination, RTF::IComment, "comment", 0,
RTF::Destination, RTF::IVersion, "version", 0,
RTF::Destination, RTF::IDoccomm, "doccomm", 0,
RTF::TOCAttr, RTF::TOCType, "tcf", 0,
RTF::TOCAttr, RTF::TOCLevel, "tcl", 0,
RTF::FontFamily, RTF::FFNil, "fnil", 0,
RTF::FontFamily, RTF::FFRoman, "froman", 0,
RTF::FontFamily, RTF::FFSwiss, "fswiss", 0,
RTF::FontFamily, RTF::FFModern, "fmodern", 0,
RTF::FontFamily, RTF::FFScript, "fscript", 0,
RTF::FontFamily, RTF::FFDecor, "fdecor", 0,
RTF::FontFamily, RTF::FFTech, "ftech", 0,
RTF::ColorName, RTF::Red, "red", 0,
RTF::ColorName, RTF::Green, "green", 0,
RTF::ColorName, RTF::Blue, "blue", 0,
RTF::CharSet, RTF::MacCharSet, "mac", 0,
RTF::CharSet, RTF::AnsiCharSet, "ansi", 0,
RTF::CharSet, RTF::PcCharSet, "pc", 0,
RTF::CharSet, RTF::PcaCharSet, "pca", 0,
RTF::TblAttr, RTF::CellBordBottom, "clbrdrb", 0,
RTF::TblAttr, RTF::CellBordTop, "clbrdrt", 0,
RTF::TblAttr, RTF::CellBordLeft, "clbrdrl", 0,
RTF::TblAttr, RTF::CellBordRight, "clbrdrr", 0,
RTF::TblAttr, RTF::RowDef, "trowd", 0,
RTF::TblAttr, RTF::RowLeft, "trql", 0,
RTF::TblAttr, RTF::RowRight, "trqr", 0,
RTF::TblAttr, RTF::RowCenter, "trqc", 0,
RTF::TblAttr, RTF::RowGapH, "trgaph", 0,
RTF::TblAttr, RTF::RowHt, "trrh", 0,
RTF::TblAttr, RTF::RowLeftEdge, "trleft", 0,
RTF::TblAttr, RTF::CellPos, "cellx", 0,
RTF::TblAttr, RTF::MergeRngFirst, "clmgf", 0,
RTF::TblAttr, RTF::MergePrevious, "clmrg", 0,
RTF::FieldAttr, RTF::FieldDirty, "flddirty", 0,
RTF::FieldAttr, RTF::FieldEdited, "fldedit", 0,
RTF::FieldAttr, RTF::FieldLocked, "fldlock", 0,
RTF::FieldAttr, RTF::FieldPrivate, "fldpriv", 0,
RTF::PosAttr, RTF::PosX, "posx", 0,
RTF::PosAttr, RTF::PosXCenter, "posxc", 0,
RTF::PosAttr, RTF::PosXInside, "posxi", 0,
RTF::PosAttr, RTF::PosXLeft, "posxl", 0,
RTF::PosAttr, RTF::PosXOutSide, "posxo", 0,
RTF::PosAttr, RTF::PosXRight, "posxr", 0,
RTF::PosAttr, RTF::PosY, "posy", 0,
RTF::PosAttr, RTF::PosYInline, "posyil", 0,
RTF::PosAttr, RTF::PosYTop, "posyt", 0,
RTF::PosAttr, RTF::PosYCenter, "posyc", 0,
RTF::PosAttr, RTF::PosYBottom, "posyb", 0,
RTF::PosAttr, RTF::AbsWid, "absw", 0,
RTF::PosAttr, RTF::TextDist, "dxfrtext", 0,
RTF::PosAttr, RTF::RPosMargV, "pvmrg", 0,
RTF::PosAttr, RTF::RPosPageV, "pvpg", 0,
RTF::PosAttr, RTF::RPosMargH, "phmrg", 0,
RTF::PosAttr, RTF::RPosPageH, "phpg", 0,
RTF::PosAttr, RTF::RPosColH, "phcol", 0,
RTF::Version, -1, "rtf", 0,
RTF::DefFont, -1, "deff", 0,
0, -1, NULL, 0
};
/*
Initialize lookup table hash values
*/
static void LookupInit ()
{
static int inited = 0;
RTFKey *rp;
if (inited == 0)
{
for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
rp->rtfKHash = Hash (rp->rtfKStr);
++inited;
}
}
/*
Determine major and minor number of control token. If it's
not found, the class turns into rtfUnknown.
*/
void RTF::Lookup (const char* s)
{
RTFKey *rp;
int hash;
++s; /* skip over the leading \ character */
hash = Hash (s);
for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
{
if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
{
rtfClass = Control;
rtfMajor = rp->rtfKMajor;
rtfMinor = rp->rtfKMinor;
return;
}
}
rtfClass = Unknown;
}
/*
Compute hash value of symbol
*/
static int Hash (const char* s)
{
char c;
int val = 0;
while ((c = *s++) != '\0')
val += (int) c;
return (val);
}
/* ---------------------------------------------------------------------- */
/*
Token comparison routines
*/
int RTF::CheckCM (int c, int major)
{
return (rtfClass == c && rtfMajor == major);
}
int RTF::CheckCMM (int c, int major, int minor)
{
return (rtfClass == c && rtfMajor == major && rtfMinor == minor);
}
int RTF::CheckMM (int major, int minor)
{
return (rtfMajor == major && rtfMinor == minor);
}